package com.tj.test.sys.controller;

import com.tj.test.sys.po.Classc;
import com.tj.test.sys.po.PST;
import com.tj.test.sys.service.IPSTService;
import com.tj.test.sys.tool.ResponseMessage;
import com.tj.test.sys.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;

@CrossOrigin
@Controller
@RequestMapping("/PST")
@Api(tags = "PST")
public class PSTController {
    @Autowired
    private IPSTService service;

    @ApiOperation("查询所有信息")
    @RequestMapping(value = "/selectAllPST",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage selectAllPST(PST pst){
        Map<String,List<PST>> map=service.selectAllPST(pst);

            return Result.success(map);

    }

    @ApiOperation("插入信息")
    @RequestMapping(value = "/insertPST",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage insertClass(PST pst){
        int temp=0;
        if (pst!=null){
            if (pst.getPersonidcard()!=null&&pst.getAccount()!=null&&pst.getPwd()!=null){
                if (pst.getStudentnumber()!=null||pst.getTeachernumber()!=null){
                   temp=service.insertPST(pst);
                   if (temp>0) {return Result.success("插入信息成功",temp);}
                   else  {return Result.error("已存在",temp);}
                }
            }
        }
        return Result.error("插入信息失败",temp);
    }
    @ApiOperation("密码验证")
    @RequestMapping(value = "/check",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage check(String account,String pwd){
        int temp=0;
        if (account!=null&&pwd!=null){
            temp=service.selectBy(account,pwd);
            if (temp==1){
                return Result.success(0);
            }
        }return Result.error(-1);
    }
}
